iT邦幫忙

2025 iThome 鐵人賽

DAY 9
0
DevOps

30 天自動化高手養成:玩轉 n8n 工作流系列 第 9

Day 9:自動將檔案上傳到 Google Drive

  • 分享至 

  • xImage
  •  

在前幾天我們處理了資料與訊息的自動化,今天換個場景:
「如何把檔案自動上傳到 Google Drive?」

這在日常工作中非常實用,例如:

  • Email 收到的附件自動存到 Google Drive
  • 自動化系統產生的報表(CSV、PDF)備份到雲端
  • 手動上傳檔案到 Webhook,n8n 自動丟進 Google Drive

今日目標

  • 了解 n8n 的 binary data 概念
  • 學會把檔案透過 Google Drive Node 自動上傳
  • 打造一個「Gmail → Google Drive 備份」的實用案例

Workflow 建立步驟

1. 準備 Google Drive 認證

  1. 在 n8n 中新增一個 Google Drive Credential
  2. 登入 Google 帳號並授權存取
  3. 選擇你想上傳的 Google Drive 資料夾

https://ithelp.ithome.com.tw/upload/images/20250923/20168203dWfH8NwCY8.png


2. 設定觸發器

根據需求不同,有幾種常見方式:

  • Gmail Trigger:監聽新郵件,抓附件
  • Webhook:外部系統或手動上傳檔案
  • Cron:定時產生或匯出檔案

這裡我們用 Gmail Trigger 做示範。

https://ithelp.ithome.com.tw/upload/images/20250923/20168203JzECLWWg4v.png


3. 處理檔案(Email Attachment)

當 Gmail Node 收到新信件時,附件會以 binary data 存放在 n8n:

  • key 通常叫 attachment_0, attachment_1
  • 每個附件都包含 fileNamemimeTypedata

https://ithelp.ithome.com.tw/upload/images/20250923/20168203aGLClT1DVW.png


4. 上傳到 Google Drive

  • Node:Google Drive

  • Operation:Upload

  • 設定參數:

    • Binary Propertyattachment_0(或用 {{$binary[0]}} 動態取)
    • Parent Folder ID:選擇 Google Drive 資料夾

n8n 就會把附件直接存到 Google Drive!

https://ithelp.ithome.com.tw/upload/images/20250923/20168203bScqLXBpYB.png


範例 Workflow

假設我們要做「Gmail 附件 → Google Drive 備份」:

https://ithelp.ithome.com.tw/upload/images/20250923/201682036AUfdFq30Z.png


成果展示

當你收到一封帶有附件的 Email,例如一份 PDF:

  • n8n 自動抓取附件
  • 自動上傳到 Google Drive 指定資料夾
  • 你再也不用手動下載 / 上傳檔案

https://ithelp.ithome.com.tw/upload/images/20250923/20168203OcN3R2dP43.png


小結

今天我們學到:

  • n8n 如何處理檔案(binary data)
  • 如何設定 Google Drive Upload
  • 建立一個「Email → Google Drive」的自動備份流程

這樣一來,任何檔案只要進到 workflow,就能自動安全地備份到 Google Drive。


上一篇
Day 8:RSS Feed 自動轉發到 Discord(使用台灣主流新聞來源)
下一篇
Day 10:網站狀態監控並自動發送異常通知
系列文
30 天自動化高手養成:玩轉 n8n 工作流12
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言